package com.hyd.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * 监测有没有网络连接的工具
 * 
 * @author llf
 * 
 */
public class NetworkConnect {
	private static String netWorkType;

	public static boolean isConnectToInternet(Context context) {
		ConnectivityManager manager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netWorkInfo = manager.getActiveNetworkInfo();
		// 返回有没有连接网络
		return netWorkInfo.isAvailable();
	}

	public static String getNetWorkType(Context context) {
		ConnectivityManager manager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netWorkInfo = manager.getActiveNetworkInfo();
		if (ConnectivityManager.TYPE_WIFI == netWorkInfo.getType()) {
			netWorkType = "wifi";
		} else if (ConnectivityManager.TYPE_MOBILE == netWorkInfo.getType()) {
			netWorkType = "mobile";
		}
		return netWorkType;
	}
}
